home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Frameworks / Sprocket Framework DR2 / Sprocket Framework Interfaces / UString.h < prev    next >
Encoding:
Text File  |  1996-05-20  |  7.1 KB  |  191 lines  |  [TEXT/CWIE]

  1. // Sprocket Framework header file
  2. // UString.h
  3. // Based on DTS Sample Code "StringUtils.c"
  4.  
  5.  
  6. #ifndef __USTRING__
  7. #define __USTRING__
  8.  
  9. #ifdef applec
  10.  
  11. #ifndef __TYPES__
  12. #include <Types.h>
  13. #endif
  14.  
  15. #endif
  16.  
  17.  
  18. /* These are duplicates of c-library functions.  The reason for duplicating them
  19. ** is so that the StringUtils code can be small and linked in with other code that
  20. ** stays resident at all times.  It is possible that when you call code to do
  21. ** something as seemingly innocent as getting the length of a string, memory can
  22. ** move.  This is because the code you are calling isn't necessarily in memory.
  23. ** If the code segment that contains the code you are calling isn't in ram, then
  24. ** it has to be loaded.  Loading the code may cause memory compaction, and therefore
  25. ** memory can move.  The pointer to the string is already pushed on the stack prior
  26. ** to the call, so if you passed a pointer into an unlocked handle, after calling
  27. ** the code, that handle may have moved, and therefore the pointer is invalid.
  28. **
  29. ** To prevent the above problem, alternate names were used for these common library
  30. ** functions.  Link this code into the same segment that holds main(), and you will
  31. ** be guaranteed that they will be in memory whenever you call them. */
  32.  
  33. short    clen(const char *cptr);
  34.     /* Return the length of the c-string.  (Same as strlen, but this function isn't
  35.     ** part of the string library.  The entire library may be more than you wish to
  36.     ** link into the code segment that holds main, so this (and other) standard
  37.     ** library function has been duplicated here. */
  38.  
  39. char    *ccat(char *s1, char *s2);
  40.     /* Catenate two c-strings. */
  41.  
  42. char    *ccpy(char *s1, char *s2);
  43.     /* Copy a c-string. */
  44.  
  45. short    pcmp(StringPtr s1, StringPtr s2);
  46.     /* Compare two pascal-strings. */
  47.  
  48. void    pcat(StringPtr d, StringPtr s);
  49.     /* Catenate two pascal-strings. */
  50.  
  51. void    pcpy(StringPtr d, StringPtr s);
  52.     /* Copy a pascal-string. */
  53.  
  54. void    c2p(char *cptr);
  55.     /* Convert a c-string to a pascal-string. */
  56.  
  57. void    p2c(StringPtr cptr);
  58.     /* Convert a pascal-string to a c-string. */
  59.  
  60.  
  61. /*****************************************************************************/
  62.  
  63. /* These are useful, relatively small routines for string manipulation.  As with the
  64. ** above calls, link them into the code segment that holds main().
  65. **
  66. ** With the below functions, you will have most of the functionality of sprintf
  67. ** using shorts and longs.  It will take more calls, but only what you call is linked
  68. ** in. */
  69.  
  70.  
  71. /**/
  72.  
  73. void    ccatchr(char *cptr, char c, short count);
  74.     /* Catenate a single character multiple times onto the designated string. */
  75.  
  76. void    ccatdec(char *cptr, long v);
  77.     /* Convert the value into text for the base-10 number and catenate it to
  78.     ** the designated string.  The value is assumed to be signed.  If you wish
  79.     ** to have an unsigned decimal value, call ccatnum with a base of 10. */
  80.  
  81. void    ccathex(char *cptr, char padChr, short minApnd, short maxApnd, long v);
  82.     /* Convert the value into text for base-16, format it, and catenate it to the
  83.     ** designated string.  ccatnum could be used, since it handles multiple bases,
  84.     ** but ccathex allows for additional common formatting and padding of the
  85.     ** hex value. */
  86.  
  87. void    ccatnum(char *cptr, long v, short base);
  88.     /* Convert the value into text for the designated base.  Catenate the text to
  89.     ** the designated string. */
  90.  
  91. void    ccpychr(char *cptr, char c, short count);
  92.     /* Copy a single character multiple times onto the designated string. */
  93.  
  94. void    ccpydec(char *cptr, long v);
  95.     /* Convert the value into text for the base-10 number and copy it into
  96.     ** the designated string.  The value is assumed to be signed.  If you wish
  97.     ** to have an unsigned decimal value, call ccpynum with a base of 10. */
  98.  
  99. void    ccpyhex(char *cptr, char padChr, short minApnd, short maxApnd, long v);
  100.     /* Convert the value into text for base-16, format it, and copy it into the
  101.     ** designated string.  ccpynum could be used, since it handles multiple bases,
  102.     ** but ccpyhex allows for additional common formatting and padding of the
  103.     ** hex value. */
  104.  
  105. void    ccpynum(char *cptr, long v, short base);
  106.     /* Convert the value into text for the designated base.  Copy the text into
  107.     ** the designated string. */
  108.  
  109. long    c2dec(char *cptr, short *charsUsed);
  110.     /* Convert the c-string to a decimal number. */
  111.  
  112. long    c2hex(char *cptr, short *charsUsed);
  113.     /* Convert the c-string to a hex number. */
  114.  
  115. long    c2num(char *cptr, short base, short *charsUsed);
  116.     /* Convert the c-string to a number.  The string can either be in decimal or hex notation. */
  117.  
  118. short    GetLastBase(Boolean handleChars);
  119.     /* Use this to find out what base c2num determined the text to be. */
  120.  
  121. /**/
  122.  
  123. short    pcmp(StringPtr s1, StringPtr s2);
  124.     /* Compare a pascal-string. */
  125.  
  126. void    pcatchr(StringPtr pptr, char c, short count);
  127.     /* Catenate a single character multiple times onto the designated string. */
  128.  
  129. void    pcatdec(StringPtr pptr, long v);
  130.     /* Convert the value into text for the base-10 number and catenate it to
  131.     ** the designated string.  The value is assumed to be signed.  If you wish
  132.     ** to have an unsigned decimal value, call pcatnum with a base of 10. */
  133.  
  134. void    pcathex(StringPtr pptr, char padChr, short minApnd, short maxApnd, long v);
  135.     /* Convert the value into text for base-16, format it, and catenate it to the
  136.     ** designated string.  pcatnum could be used, since it handles multiple bases,
  137.     ** but pcathex allows for additional common formatting and padding of the
  138.     ** hex value. */
  139.  
  140. long    pcatnum(StringPtr pptr, long v, short base);
  141.     /* Convert the value into text for the designated base.  Catenate the text to
  142.     ** the designated string. */
  143.  
  144. void    pcpychr(StringPtr pptr, char c, short count);
  145.     /* Copy a single character multiple times onto the designated string. */
  146.  
  147. void    pcpydec(StringPtr pptr, long v);
  148.     /* Convert the value into text for the base-10 number and copy it into
  149.     ** the designated string.  The value is assumed to be signed.  If you wish
  150.     ** to have an unsigned decimal value, call pcpynum with a base of 10. */
  151.  
  152. void    pcpyhex(StringPtr pptr, char padChr, short minApnd, short maxApnd, long v);
  153.     /* Convert the value into text for base-16, format it, and copy it into the
  154.     ** designated string.  pcpynum could be used, since it handles multiple bases,
  155.     ** but pcpyhex allows for additional common formatting and padding of the
  156.     ** hex value. */
  157.  
  158. void    pcpynum(StringPtr pptr, long v, short base);
  159.     /* Convert the value into text for the designated base.  Copy the text into
  160.     ** the designated string. */
  161.  
  162. long    p2dec(StringPtr pptr, short *charsUsed);
  163.     /* Convert the pascal-string to a decimal number. */
  164.  
  165. long    p2hex(StringPtr pptr, short *charsUsed);
  166.     /* Convert the pascal-string to a hex number. */
  167.  
  168. long    p2num(StringPtr pptr, short base, short *charsUsed);
  169.     /* Convert the pascal-string to a number.  String can either be in decimal or hex notation. */
  170.  
  171. /**/
  172.  
  173. short    GetHexByte(char *cptr);
  174.  
  175. Boolean    EqualHandle(void *h1, void *h2);
  176.     /* This function checks to see if two handles are identical. */
  177.  
  178. Boolean    EqualData(void *v1, void *v2, long size);
  179.     /* This function checks to see if two blocks of data are identical. */
  180.  
  181. void    SetMem(void *vptr, unsigned char c, unsigned long len);
  182.  
  183.     /* Analagous to GetIndString */
  184. OSErr SetIndString(StringPtr theStr, short resID, short strIndex);
  185.  
  186.  
  187. #endif
  188.  
  189.  
  190.  
  191.